package com.yifi.common.utils;

import java.io.File;

import com.jfinal.kit.*;

import cn.hutool.core.io.FileUtil;

public class FileUtils extends FileUtil{

	public static String GetRootPath() {

		//return Controller.getSession().getServletContext().getRealPath("/WEB-INF/upload");
		//return Controller.getSession().getServletContext().getRealPath("");
		//return JFinal.me().getServletContext().getRealPath("");
		return PathKit.getWebRootPath();
	}
	
	public static String getWebUploadPath() {
		String uploadPath = GetRootPath();
		return uploadPath;
	}

	public static String getUploadPath() {
		return GetRootPath() + "/WEB-INF/upload/";
		
		/*String uploadPath = GetRootPath() + "/upload/";// yf_stmp/upload/
		return com.jfinal.kit.PropKit.get("path_upload", uploadPath);*/
	}
	public static String getConfigUploadPath() {
		String  uploadPath = GetRootPath() + "/upload/";//yf_stmp/upload/
		return PropKit.get("path_upload", uploadPath);
	}
	
	public static String getDownDir()
	{
		return getConfigUploadPath()+"/down/";
	}

	public static String getDatePath() {
		String datepath = DateUtils.parseDateToStr("yyyy-MM",DateUtils.getNowDate());//当前月份目录
		return  "attach/"+datepath+"/";
	}
	
	public static String getExtName(File file)
	{
		String fileName=getName(file);
		String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
		
		return suffix;
	}
	
	public static boolean deleteFile(String attachPath)
	{
		attachPath=getConfigUploadPath()+attachPath;
		return FileUtil.del(attachPath);
	}
}
